package com.qianmang.damawangticket.bean;

import android.os.Parcel;
import android.os.Parcelable;

import androidx.annotation.DrawableRes;

/**
 * 赚钱的app
 */
public class AppBean implements Comparable<AppBean>, Parcelable {

    public static  final String APP_BEAN ="AppBean";

    public static final int APP_TYPE_WX = 0x1;////微信
    public static final int APP_TYPE_MESSAGE = 0x10;//需要发送消息类
    public static final int APP_TYPE_KEYBOARD = 0x100;////
    public static final int APP_TYPE_VIDEO = 0;//视屏类app
    public static final int APP_TYPE_NEWS = 0x2;//新闻类
    public static final int APP_TYPE_READ = 0x3;//小说类
    public static final int APP_CUSTOM = 0x5;//需要发送消息类
    private String appName; //app名称
    private int sort; //app名称
    private String downloadAddress;
    private String packageName;
    private String launcherClassName;
    @DrawableRes
    private int icLauncherId;
    private long time;//已经进行的时长；
    private long duration;//总共需要执行的时长
    private int money; //金币数量
    private boolean isSelect = false;
    private long startTime; //开始时间 毫秒值
    private String message = "默认消息";
    private boolean mustSet = false; //是否必须要设置
    private String authCodeMagic="";

    /**
     * {@link AppBean#APP_TYPE_NEWS}新闻刷金币app {@link AppBean#APP_TYPE_WX}微信
     * {@link AppBean#APP_TYPE_VIDEO}视频类app {@link AppBean#APP_TYPE_READ}小说类
     */
    private int appType = 0;


    private String appVersion; //需要的版本
    private boolean isInstall = false; //该app是否安装
    private String installVersion; //安装的版本

    public AppBean() {
    }


    public AppBean(String appName, long duration, String packageName, String launcherClassName) {
        this.appName = appName;
        this.duration = duration;
        this.packageName = packageName;
        this.launcherClassName = launcherClassName;
    }

    public String getAppName() {
        return appName;
    }

    public AppBean setAppName(String appName) {
        this.appName = appName;
        return this;
    }

    public long getTime() {
        return time;
    }

    public AppBean setTime(long time) {
        this.time = time;
        return this;
    }

    public int getMoney() {
        return money;
    }

    public AppBean setMoney(int money) {
        this.money = money;
        return this;
    }

    public long getDuration() {
        return duration;
    }

    public AppBean setDuration(long duration) {
        this.duration = duration;
        return this;
    }


    public String getPackageName() {
        return packageName;
    }

    public AppBean setPackageName(String packageName) {
        this.packageName = packageName;
        return this;
    }

    public String getLauncherClassName() {
        return launcherClassName;
    }

    public AppBean setLauncherClassName(String launcherClassName) {
        this.launcherClassName = launcherClassName;
        return this;
    }

    public boolean isSelect() {
        return isSelect;
    }

    public long getStartTime() {
        return startTime;
    }

    public AppBean setStartTime(long startTime) {
        this.startTime = startTime;
        return this;
    }

    public AppBean setSelect(boolean select) {
        isSelect = select;
        return this;
    }

    public String getDownloadAddress() {
        return downloadAddress;
    }

    public AppBean setDownloadAddress(String downloadAddress) {
        this.downloadAddress = downloadAddress;
        return this;

    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof AppBean)) return false;

        AppBean appBean = (AppBean) o;

        return getPackageName() != null ? getPackageName().equals(appBean.getPackageName()) : appBean.getPackageName() == null;
    }

    @Override
    public int hashCode() {
        return getPackageName() != null ? getPackageName().hashCode() : 0;
    }

    /**
     * 包名和版本号一致
     *
     * @param
     * @return
     */


    public int getAppType() {
        return appType;
    }

    public AppBean setAppType(int appType) {
        this.appType = appType;
        return this;

    }

    @DrawableRes
    public int getIcLauncherId() {
        return icLauncherId;
    }

    public AppBean setIcLauncherId(@DrawableRes int icLauncherId) {
        this.icLauncherId = icLauncherId;
        return this;
    }

    public String getAppVersion() {
        return appVersion;
    }

    public AppBean setAppVersion(String appVersion) {
        this.appVersion = appVersion;
        return this;
    }

    public boolean isInstall() {
        return isInstall;
    }

    public AppBean setInstall(boolean install) {
        isInstall = install;
        return this;
    }

    public String getInstallVersion() {
        return installVersion;
    }

    public void setInstallVersion(String installVersion) {
        this.installVersion = installVersion;
    }

    public int getSort() {
        return sort;
    }

    public void setSort(int sort) {
        this.sort = sort;
    }


    public String getAuthCodeMagic() {
        return authCodeMagic;
    }

    public AppBean setAuthCodeMagic(String authCodeMagic) {
        this.authCodeMagic = authCodeMagic;
        return this;
    }

    public void copy(AppBean appBean) {
        this.setSelect(appBean.isSelect);
        this.setDuration(appBean.getDuration());
        this.setSort(appBean.getSort());
    }

    @Override
    public int compareTo(AppBean o) {
        return this.getSort() - o.getSort();
    }



    @Override
    public String toString() {
        return "AppBean{" +
                "appName='" + appName + '\'' +
                '}';
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeString(this.appName);
        dest.writeInt(this.sort);
        dest.writeString(this.downloadAddress);
        dest.writeString(this.packageName);
        dest.writeString(this.launcherClassName);
        dest.writeInt(this.icLauncherId);
        dest.writeLong(this.time);
        dest.writeLong(this.duration);
        dest.writeInt(this.money);
        dest.writeByte(this.isSelect ? (byte) 1 : (byte) 0);
        dest.writeLong(this.startTime);
        dest.writeString(this.message);
        dest.writeByte(this.mustSet ? (byte) 1 : (byte) 0);
        dest.writeString(this.authCodeMagic);
        dest.writeInt(this.appType);
        dest.writeString(this.appVersion);
        dest.writeByte(this.isInstall ? (byte) 1 : (byte) 0);
        dest.writeString(this.installVersion);
    }

    protected AppBean(Parcel in) {
        this.appName = in.readString();
        this.sort = in.readInt();
        this.downloadAddress = in.readString();
        this.packageName = in.readString();
        this.launcherClassName = in.readString();
        this.icLauncherId = in.readInt();
        this.time = in.readLong();
        this.duration = in.readLong();
        this.money = in.readInt();
        this.isSelect = in.readByte() != 0;
        this.startTime = in.readLong();
        this.message = in.readString();
        this.mustSet = in.readByte() != 0;
        this.authCodeMagic = in.readString();
        this.appType = in.readInt();
        this.appVersion = in.readString();
        this.isInstall = in.readByte() != 0;
        this.installVersion = in.readString();
    }

    public static final Creator<AppBean> CREATOR = new Creator<AppBean>() {
        @Override
        public AppBean createFromParcel(Parcel source) {
            return new AppBean(source);
        }

        @Override
        public AppBean[] newArray(int size) {
            return new AppBean[size];
        }
    };
}
